<html>
<head><meta charset="utf-8"><title>Promotion and reborrows · t-compiler/const-eval · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/index.html">t-compiler/const-eval</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Promotion.20and.20reborrows.html">Promotion and reborrows</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="214489406"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Promotion%20and%20reborrows/near/214489406" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Promotion.20and.20reborrows.html#214489406">(Oct 25 2020 at 13:23)</a>:</h4>
<p>I am trying to understand the effect of <a href="https://github.com/rust-lang/rust/blob/5171cc76c264fd46f32e140c2e460c77ca87d5e5/compiler/rustc_mir/src/transform/promote_consts.rs#L686">this code</a> in promotion.<br>
Removing it makes only one test case fail: <a href="https://github.com/rust-lang/rust/blob/5171cc76c264fd46f32e140c2e460c77ca87d5e5/src/test/ui/statics/static-promotion.rs#L17">this one</a>.</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">struct</span> <span class="nc">A</span><span class="o">&lt;</span><span class="n">T</span>: <span class="o">'</span><span class="nb">static</span><span class="o">&gt;</span><span class="p">(</span><span class="o">&amp;'</span><span class="nb">static</span><span class="w"> </span><span class="n">T</span><span class="p">);</span><span class="w"></span>
<span class="k">struct</span> <span class="nc">B</span><span class="o">&lt;</span><span class="n">T</span>: <span class="o">'</span><span class="nb">static</span> <span class="o">+</span><span class="w"> </span><span class="o">?</span><span class="nb">Sized</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">x</span>: <span class="kp">&amp;</span><span class="o">'</span><span class="nb">static</span> <span class="nc">T</span><span class="p">,</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
<span class="k">static</span><span class="w"> </span><span class="n">STR</span>: <span class="kp">&amp;</span><span class="o">'</span><span class="nb">static</span> <span class="p">[</span><span class="kt">u8</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">b"hi"</span><span class="p">;</span><span class="w"></span>
<span class="k">static</span><span class="w"> </span><span class="n">C</span>: <span class="nc">A</span><span class="o">&lt;</span><span class="n">B</span><span class="o">&lt;</span><span class="n">B</span><span class="o">&lt;</span><span class="p">[</span><span class="kt">u8</span><span class="p">]</span><span class="o">&gt;&gt;&gt;</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">A</span><span class="p">(</span><span class="o">&amp;</span><span class="n">B</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="n">x</span>: <span class="kp">&amp;</span><span class="nc">B</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">x</span>: <span class="nc">STR</span><span class="w"> </span><span class="p">},</span><span class="w"></span>
<span class="w">    </span><span class="p">})</span><span class="w"></span>
<span class="p">};</span><span class="w"></span>
</code></pre></div>

<p>But that is very confusing, since I cannot see a reborrow anywhere in that code? <span class="user-mention" data-user-id="124288">@oli</span> <span class="user-mention" data-user-id="118594">@ecstatic-morse</span>  any idea what is going on?</p>



<a name="214489540"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Promotion%20and%20reborrows/near/214489540" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Promotion.20and.20reborrows.html#214489540">(Oct 25 2020 at 13:26)</a>:</h4>
<p>I think this comment is actually wrong</p>



<a name="214489545"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Promotion%20and%20reborrows/near/214489545" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Promotion.20and.20reborrows.html#214489545">(Oct 25 2020 at 13:26)</a>:</h4>
<p><code>_5 = (*_6); </code> is in the MIR of <code>C</code></p>



<a name="214489547"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Promotion%20and%20reborrows/near/214489547" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Promotion.20and.20reborrows.html#214489547">(Oct 25 2020 at 13:26)</a>:</h4>
<p>and it is a deref of a double reference</p>



<a name="214489578"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Promotion%20and%20reborrows/near/214489578" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Promotion.20and.20reborrows.html#214489578">(Oct 25 2020 at 13:27)</a>:</h4>
<p>aaah, and that double reference happens because mentioning a static item is <code>*&amp;STR</code></p>



<a name="214489626"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Promotion%20and%20reborrows/near/214489626" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Promotion.20and.20reborrows.html#214489626">(Oct 25 2020 at 13:28)</a>:</h4>
<p>I'm not sure this is the intended use case of that piece of code</p>



<a name="214489718"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Promotion%20and%20reborrows/near/214489718" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Promotion.20and.20reborrows.html#214489718">(Oct 25 2020 at 13:31)</a>:</h4>
<p>although... this is part of <code>Rvalue::Ref</code></p>



<a name="214489729"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Promotion%20and%20reborrows/near/214489729" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Promotion.20and.20reborrows.html#214489729">(Oct 25 2020 at 13:31)</a>:</h4>
<p>so... you're right, this shouldn't be part of anything here. Did you try dumping the MIR before promotion?</p>



<a name="214489733"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Promotion%20and%20reborrows/near/214489733" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Promotion.20and.20reborrows.html#214489733">(Oct 25 2020 at 13:31)</a>:</h4>
<p>maybe it's just the pre-promotion MIR that contains the reborrow</p>



<a name="214490166"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Promotion%20and%20reborrows/near/214490166" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Promotion.20and.20reborrows.html#214490166">(Oct 25 2020 at 13:42)</a>:</h4>
<p>is "PromoteTemps" the right pass name?</p>



<a name="214490175"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Promotion%20and%20reborrows/near/214490175" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Promotion.20and.20reborrows.html#214490175">(Oct 25 2020 at 13:42)</a>:</h4>
<div class="codehilite"><pre><span></span><code>// MIR for `C` before PromoteTemps

static C: A&lt;B&lt;B&lt;[u8]&gt;&gt;&gt; = {
    let mut _0: A&lt;B&lt;B&lt;[u8]&gt;&gt;&gt;;           // return place in scope 0 at src/test/ui/statics/static-promotion.rs:16:11: 16:24
    let mut _1: &amp;B&lt;B&lt;[u8]&gt;&gt;;             // in scope 0 at src/test/ui/statics/static-promotion.rs:17:7: 19:6
    let _2: &amp;B&lt;B&lt;[u8]&gt;&gt;;                 // in scope 0 at src/test/ui/statics/static-promotion.rs:17:7: 19:6
    let _3: B&lt;B&lt;[u8]&gt;&gt;;                  // in scope 0 at src/test/ui/statics/static-promotion.rs:17:8: 19:6
    let mut _4: &amp;B&lt;[u8]&gt;;                // in scope 0 at src/test/ui/statics/static-promotion.rs:18:12: 18:25
    let _5: &amp;B&lt;[u8]&gt;;                    // in scope 0 at src/test/ui/statics/static-promotion.rs:18:12: 18:25
    let _6: B&lt;[u8]&gt;;                     // in scope 0 at src/test/ui/statics/static-promotion.rs:18:13: 18:25
    let mut _7: &amp;[u8];                   // in scope 0 at src/test/ui/statics/static-promotion.rs:18:20: 18:23
    let mut _8: &amp;&amp;[u8];                  // in scope 0 at src/test/ui/statics/static-promotion.rs:18:20: 18:23

    bb0: {
        StorageLive(_1);                 // scope 0 at src/test/ui/statics/static-promotion.rs:17:7: 19:6
        StorageLive(_2);                 // scope 0 at src/test/ui/statics/static-promotion.rs:17:7: 19:6
        StorageLive(_3);                 // scope 0 at src/test/ui/statics/static-promotion.rs:17:8: 19:6
        StorageLive(_4);                 // scope 0 at src/test/ui/statics/static-promotion.rs:18:12: 18:25
        StorageLive(_5);                 // scope 0 at src/test/ui/statics/static-promotion.rs:18:12: 18:25
        StorageLive(_6);                 // scope 0 at src/test/ui/statics/static-promotion.rs:18:13: 18:25
        StorageLive(_7);                 // scope 0 at src/test/ui/statics/static-promotion.rs:18:20: 18:23
        StorageLive(_8);                 // scope 0 at src/test/ui/statics/static-promotion.rs:18:20: 18:23
        _8 = const {alloc1: &amp;&amp;[u8]};     // scope 0 at src/test/ui/statics/static-promotion.rs:18:20: 18:23
                                         // ty::Const
                                         // + ty: &amp;&amp;[u8]
                                         // + val: Value(Scalar(alloc1))
                                         // mir::Constant
                                         // + span: src/test/ui/statics/static-promotion.rs:18:20: 18:23
                                         // + literal: Const { ty: &amp;&amp;[u8], val: Value(Scalar(alloc1)) }
        _7 = (*_8);                      // scope 0 at src/test/ui/statics/static-promotion.rs:18:20: 18:23
        _6 = B::&lt;[u8]&gt; { x: move _7 };   // scope 0 at src/test/ui/statics/static-promotion.rs:18:13: 18:25
        _5 = &amp;_6;                        // scope 0 at src/test/ui/statics/static-promotion.rs:18:12: 18:25
        _4 = &amp;(*_5);                     // scope 0 at src/test/ui/statics/static-promotion.rs:18:12: 18:25
        _3 = B::&lt;B&lt;[u8]&gt;&gt; { x: move _4 }; // scope 0 at src/test/ui/statics/static-promotion.rs:17:8: 19:6
        _2 = &amp;_3;                        // scope 0 at src/test/ui/statics/static-promotion.rs:17:7: 19:6
        _1 = &amp;(*_2);                     // scope 0 at src/test/ui/statics/static-promotion.rs:17:7: 19:6
        _0 = A::&lt;B&lt;B&lt;[u8]&gt;&gt;&gt;(move _1);   // scope 0 at src/test/ui/statics/static-promotion.rs:17:5: 19:7
        StorageDead(_8);                 // scope 0 at src/test/ui/statics/static-promotion.rs:20:1: 20:2
        StorageDead(_6);                 // scope 0 at src/test/ui/statics/static-promotion.rs:20:1: 20:2
        StorageDead(_5);                 // scope 0 at src/test/ui/statics/static-promotion.rs:20:1: 20:2
        StorageDead(_3);                 // scope 0 at src/test/ui/statics/static-promotion.rs:20:1: 20:2
        StorageDead(_2);                 // scope 0 at src/test/ui/statics/static-promotion.rs:20:1: 20:2
        return;                          // scope 0 at src/test/ui/statics/static-promotion.rs:16:1: 20:3
    }
}

alloc1 (static: STR, size: 16, align: 8) {
    ╾───────alloc0────────╼ 02 00 00 00 00 00 00 00 │ ╾──────╼........
}

alloc0 (size: 2, align: 1) {
    68 69                                           │ hi
}
</code></pre></div>



<a name="214490201"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Promotion%20and%20reborrows/near/214490201" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Promotion.20and.20reborrows.html#214490201">(Oct 25 2020 at 13:43)</a>:</h4>
<p>so for some reason it inserts a bunch of reborrows... I thought we only did that for mutable references?</p>



<a name="214490249"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Promotion%20and%20reborrows/near/214490249" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Promotion.20and.20reborrows.html#214490249">(Oct 25 2020 at 13:44)</a>:</h4>
<p>I also don't get why this test <em>needs</em> that special case to work, it seems like perfectly promotable things everywhere</p>



<a name="214490336"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Promotion%20and%20reborrows/near/214490336" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Promotion.20and.20reborrows.html#214490336">(Oct 25 2020 at 13:46)</a>:</h4>
<p>(that special case exists in <code>validate_rvalue</code> but not in the mostly-duplicate code in <code>validate_candidate</code> so I was seeing if I can get rid of it)</p>



<a name="214490774"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Promotion%20and%20reborrows/near/214490774" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Promotion.20and.20reborrows.html#214490774">(Oct 25 2020 at 13:56)</a>:</h4>
<p>yea, it looks wrong for there to be reborrows inserted, but maybe it's hard to figure that out in mir building?</p>



<a name="214490794"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Promotion%20and%20reborrows/near/214490794" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Promotion.20and.20reborrows.html#214490794">(Oct 25 2020 at 13:57)</a>:</h4>
<p>probably -- and that is probably why promotion special-cases reborrows</p>



<a name="214490856"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Promotion%20and%20reborrows/near/214490856" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Promotion.20and.20reborrows.html#214490856">(Oct 25 2020 at 13:58)</a>:</h4>
<p>hm the mroe I learna bout it the more I am actually surprised by how <em>similar</em> the code in <code>validate_candidate</code> and <code>validate_rvalue</code> is... at least I think it is the case that when we promote such a candidate, we only promote the <em>base</em> and still do the projections at runtime? that is the only way <code>&amp;promoted[runtime_idx]</code> can work...</p>



<a name="214490872"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Promotion%20and%20reborrows/near/214490872" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Promotion.20and.20reborrows.html#214490872">(Oct 25 2020 at 13:59)</a>:</h4>
<p>so I don't understand how this <code>has_mut_interior</code> check (removing the flag when... some condition is met) can make sense on both places</p>



<a name="214491467"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Promotion%20and%20reborrows/near/214491467" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Promotion.20and.20reborrows.html#214491467">(Oct 25 2020 at 14:12)</a>:</h4>
<p><a href="https://github.com/RalfJung/rust/commit/0f57b9f0473bfc23652ad8cde42c1dbd31a172e0">this patch</a> does not seem to make any of our existing tests fail...</p>



<a name="214491663"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Promotion%20and%20reborrows/near/214491663" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Promotion.20and.20reborrows.html#214491663">(Oct 25 2020 at 14:16)</a>:</h4>
<p>lol, <a href="https://github.com/RalfJung/rust/commit/686deea3822">removing the other has_interior_mut special case</a> also doesn't make any test fail^^ <span class="user-mention" data-user-id="124288">@oli</span> can you craft testcases for one/both of them?</p>



<a name="214494687"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Promotion%20and%20reborrows/near/214494687" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Promotion.20and.20reborrows.html#214494687">(Oct 25 2020 at 15:19)</a>:</h4>
<p>I would guess without those <code>let _: &amp;'static _ = &amp;(Cell::new(1), 2).0;</code> would successfully compile?</p>



<a name="214495380"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Promotion%20and%20reborrows/near/214495380" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oliver <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Promotion.20and.20reborrows.html#214495380">(Oct 25 2020 at 15:33)</a>:</h4>
<p>What is this snippet doing?<br>
<code>[proj_base @ .., ProjectionElem::Deref]</code></p>



<a name="214496967"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Promotion%20and%20reborrows/near/214496967" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Promotion.20and.20reborrows.html#214496967">(Oct 25 2020 at 16:07)</a>:</h4>
<p>This is a pattern that requires the last element to be deref and yields everything but the last element as a slice in the <code>proj_base</code> binding</p>



<a name="214497048"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Promotion%20and%20reborrows/near/214497048" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oliver <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Promotion.20and.20reborrows.html#214497048">(Oct 25 2020 at 16:08)</a>:</h4>
<p>And projection is the same as it's used here:<br>
<a href="https://rustc-dev-guide.rust-lang.org/queries/incremental-compilation-in-detail.html#the-projection-query-pattern">https://rustc-dev-guide.rust-lang.org/queries/incremental-compilation-in-detail.html#the-projection-query-pattern</a></p>



<a name="214498701"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Promotion%20and%20reborrows/near/214498701" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Promotion.20and.20reborrows.html#214498701">(Oct 25 2020 at 16:42)</a>:</h4>
<p><span class="user-mention silent" data-user-id="124288">oli</span> <a href="#narrow/stream/146212-t-compiler.2Fconst-eval/topic/Promotion.20and.20reborrows/near/214494687">said</a>:</p>
<blockquote>
<p>I would guess without those <code>let _: &amp;'static _ = &amp;(Cell::new(1), 2).0;</code> would successfully compile?</p>
</blockquote>
<p>these snippets allow <em>more</em> promoteds</p>



<a name="214498710"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Promotion%20and%20reborrows/near/214498710" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Promotion.20and.20reborrows.html#214498710">(Oct 25 2020 at 16:42)</a>:</h4>
<p>they are about clearing the <code>has_mut_interior</code> flag</p>



<a name="214498815"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Promotion%20and%20reborrows/near/214498815" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Promotion.20and.20reborrows.html#214498815">(Oct 25 2020 at 16:44)</a>:</h4>
<p><span class="user-mention silent" data-user-id="124288">oli</span> <a href="#narrow/stream/146212-t-compiler.2Fconst-eval/topic/Promotion.20and.20reborrows/near/214494687">said</a>:</p>
<blockquote>
<p>I would guess without those <code>let _: &amp;'static _ = &amp;(Cell::new(1), 2).0;</code> would successfully compile?</p>
</blockquote>
<p>nope, I added that case to <code>promote-not.rs</code> and it still passes</p>



<a name="214499427"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Promotion%20and%20reborrows/near/214499427" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Promotion.20and.20reborrows.html#214499427">(Oct 25 2020 at 16:55)</a>:</h4>
<p>hm, I thought <code>let _val: &amp;'static _ = &amp;(Cell::new(1), 2).1;</code> was supposed to work but that is already rejected on stable</p>



<a name="214499759"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Promotion%20and%20reborrows/near/214499759" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Promotion.20and.20reborrows.html#214499759">(Oct 25 2020 at 17:00)</a>:</h4>
<p>ah, <code>let _val: &amp;'static _ = &amp;(Cell::new(1), 2).1;</code> <em>inside a <code>const</code>/<code>static</code></em> fails to promote without this special case</p>



<a name="214499856"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Promotion%20and%20reborrows/near/214499856" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Promotion.20and.20reborrows.html#214499856">(Oct 25 2020 at 17:02)</a>:</h4>
<p>I think in a <code>fn</code>/<code>const fn</code> we can never even reach that case as we do not promote anything that <em>introduces</em> interior mutability</p>



<a name="214499989"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Promotion%20and%20reborrows/near/214499989" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Promotion.20and.20reborrows.html#214499989">(Oct 25 2020 at 17:04)</a>:</h4>
<p><del>oh, in a <code>const</code> this cannot happen either as we do not permit interior mutability there</del></p>



<a name="214499997"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Promotion%20and%20reborrows/near/214499997" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Promotion.20and.20reborrows.html#214499997">(Oct 25 2020 at 17:04)</a>:</h4>
<p><del>so this is only for inside a <code>static</code> initializer</del><br>
sorry I tested wrong</p>



<a name="214500330"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Promotion%20and%20reborrows/near/214500330" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Promotion.20and.20reborrows.html#214500330">(Oct 25 2020 at 17:11)</a>:</h4>
<p>I suggest we do a crater experiment, unless <span class="user-mention" data-user-id="124288">@oli</span> can come up with more testcases for this:<br>
<a href="https://github.com/rust-lang/rust/pull/78363">https://github.com/rust-lang/rust/pull/78363</a></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>